package com.example.webrtcproject;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

/**
 *
 *
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private String[] permissions = {Manifest.permission.CAMERA,Manifest.permission.RECORD_AUDIO};
    private EditText roomEdit;
    private String roomName;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button callBtn = findViewById(R.id.call_btn);
        Button receiveBtn = findViewById(R.id.receive_button);
        roomEdit = findViewById(R.id.room_name);
        roomEdit.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                roomName = s.toString();
            }
        });
        callBtn.setOnClickListener(this);
        receiveBtn.setOnClickListener(this);
        requestPermissions(permissions,1);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.call_btn:
                if(TextUtils.isEmpty(roomName)){
                    ToastUtil.showToast(MainActivity.this,"请输入房间号");
                    return;
                }
                Intent intent = new Intent(this,WebRtcActivity.class);
                intent.putExtra("roomName",roomName);
                startActivity(intent);
                break;
            case R.id.receive_button:
//                Intent intent1 = new Intent(this,WebRtcReceiveActivity.class);
//                startActivity(intent1);
                break;
            default:
                break;
        }

    }
}
